package com.ruoyi.energy.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.NyMeterManagement;
import com.ruoyi.energy.service.INyMeterManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 仪表管理Controller
 *
 * @author cjie
 * @date 2021-07-29
 */
@Api(tags = " 仪表管理")
@RestController
@RequestMapping("/nyMeterManagement")
public class NyMeterManagementController extends BaseController {
    @Autowired
    private INyMeterManagementService nyMeterManagementService;

    /**
     * 查询仪表管理列表
     */
    @ApiOperation(value="查询仪表管理列表", notes="查询仪表管理列表")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:list")
    @GetMapping("/list")
    public TableDataInfo list(NyMeterManagement nyMeterManagement) {
        startPage();
        List<NyMeterManagement> list = nyMeterManagementService.selectNyMeterManagementList(nyMeterManagement);
        return getDataTable(list);
    }

    /**
     * 导出仪表管理列表
     */
    @ApiOperation(value="导出仪表管理列表", notes="导出仪表管理列表")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:export")
    @Log(title = "仪表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NyMeterManagement nyMeterManagement) throws IOException {
        List<NyMeterManagement> list = nyMeterManagementService.selectNyMeterManagementList(nyMeterManagement);
        ExcelUtil<NyMeterManagement> util = new ExcelUtil<NyMeterManagement>(NyMeterManagement.class);
        util.exportExcel(response, list, "仪表管理数据");
    }
    /**
     * 获取仪表管理详细信息
     */
    @ApiOperation(value="获取仪表管理详细信息", notes="获取仪表管理详细信息")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(nyMeterManagementService.selectNyMeterManagementById(id));
    }

    /**
     * 新增仪表管理
     */
    @ApiOperation(value="新增仪表管理", notes="新增仪表管理")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:add")
    @Log(title = "仪表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NyMeterManagement nyMeterManagement) {
        return toAjax(nyMeterManagementService.insertNyMeterManagement(nyMeterManagement));
    }

    /**
     * 计算私表汇总
     */
    @ApiOperation(value="分摊管理", notes="分摊管理")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:edit")
    @Log(title = "分摊管理", businessType = BusinessType.UPDATE)
    @GetMapping(value="/share/{id}")
    public AjaxResult share(@PathVariable("id") String id ) {
        return toAjax(nyMeterManagementService.shareNyMeterManagement(id));
    }

    /**
     * 计算私表汇总
     */
    @ApiOperation(value="修改仪表管理", notes="修改仪表管理")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:edit")
    @Log(title = "仪表管理", businessType = BusinessType.UPDATE)
    @GetMapping(value="/compute/{id}")
    public AjaxResult compute(@PathVariable("id") String id ) {
        return toAjax(nyMeterManagementService.computeNyMeterManagement(id));
    }

    /**
     * 修改仪表管理
     */
    @ApiOperation(value="修改仪表管理", notes="修改仪表管理")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:edit")
    @Log(title = "仪表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NyMeterManagement nyMeterManagement) {
        return toAjax(nyMeterManagementService.updateNyMeterManagement(nyMeterManagement));
    }

    /**
     * 删除仪表管理
     */
    @ApiOperation(value="删除仪表管理", notes="删除仪表管理")
    @ApiImplicitParam(name = "ids", value = "仪表管理ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:nyMeterManagement:remove")
    @Log(title = "仪表管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(nyMeterManagementService.deleteNyMeterManagementByIds(ids));
    }
}
